from fake_useragent import UserAgent
import requests
import os
path = 'images'
if not os.path.exists(path):
    os.mkdir(path)

with open('files/mv.csv', mode='r', encoding='utf-8')as f:
    f.readline()
    for line in f:
        print(line)
        user_id, username, url = line.strip().split(',')
        print(username, url)
        # 1.根据url下载图片
        res = requests.get(
            url=url,
            headers = {
                'User-Agent':UserAgent.Chrome()
            }
        )
        data = res.content
        # 2.将图片的内容写入到文件中
        with open('images/{}.png'.format(username),mode='wb')as file:
            file.write(data)
